Differential binding of the three PURA HeLa iCLIPs - 7: 2 oe vs 2 oe

Author

Melina Klostermann

Published

November 3, 2023

Show code
install.packages("ggplot2")
#install.packages("ggpubr")
install.packages("ggrastr")
install.packages("ggpointdensity")
install.packages("viridis")

BiocManager::install("BindingSiteFinder")
BiocManager::install("GenomicFeatures")
BiocManager::install("DESeq2")

1 Input

Show code
# path for output
outpath <- "~/Thesis/Thesis_code/PURA/07_Differential_binding/"

bds <- readRDS(paste0(outpath, "bds_merge_oe_2v2.rds"))

bds
Dataset:  oe_oe
Object of class BSFDataSet 
#N Ranges:  147,893 
Width ranges:  5 
#N Samples:  4 
#N Conditions:  2 
Show code
# gene annotation
annotation <- readRDS("~/PURA/Molitor-et-al-2022/annotation.rds")
anno_txdb <- makeTxDbFromGRanges(annotation)

gns = genes(anno_txdb)
gns$gene_id = sub("\\..*", "", gns$gene_id)
idx = match(gns$gene_id, annotation$gene_id)
elementMetadata(gns) = cbind(elementMetadata(gns), elementMetadata(annotation)[idx,])
names(gns) = sub("\\..*", "", names(gns))
meta = data.frame(gene_id = gns$gene_id, gene_name = gns$gene_name, gene_type = gns$gene_type)
mcols(gns) = meta
gns$geneID = names(gns)

cdseq = cds(anno_txdb)
intrns = unlist(intronsByTranscript(anno_txdb))
utrs3 = unlist(threeUTRsByTranscript(anno_txdb))
utrs5 = unlist(fiveUTRsByTranscript(anno_txdb))
trl = GRangesList(CDS = cdseq, Intron = intrns, UTR3 = utrs3, UTR5 = utrs5)

# saveRDS(trl, paste0(outpath, "transcript_region_list_test.rds"))

2 Assign genes and regions

Show code
bds <- assignToGenes(bds, anno.genes = gns, overlaps = "frequency")

# saveRDS(bds, paste0(outpath, "bds_test.rds"))
#bds <- assignToTranscriptRegions(bds, anno.transcriptRegionList = trl, overlaps.rule = c("UTR3", "UTR5", "CDS", "Intron"))

# bds <- assignToTranscriptRegions(bds, anno.transcriptRegionList = trl, overlaps = "frequency")
# getRanges(bds)

3 Calculate background

Show code
# compute the binding site and background coverage
bds = calculateBsBackground(bds, anno.genes = gns)

# filter background 
bds = filterBsBackground(bds,
                          minCounts.cutoff = 1000,
                         balanceBackground.cutoff.bs = 0.3,
                         balanceBackground.cutoff.bg = 0.7)

plotBsBackgroundFilter(bds, filter = "minCounts")

Show code
plotBsBackgroundFilter(bds, filter = "balanceBackground")

Show code
plotBsBackgroundFilter(bds, filter = "balanceCondition")

4 Caluclate Changes

Show code
bds <- calculateBsFoldChange(bds)

5 Changes

5.1 binding changes

Show code
plotBsMA(bds, what = "bs")

Show code
plotBsVolcano(bds, what = "bs")

5.2 background changes

Show code
plotBsMA(bds, what = "bg")

Show code
plotBsVolcano(bds, what = "bg")

Show code
bs <- getRanges(bds) |> as.data.frame()

Number of binding sites: 146993

Number of sig changing binding sites: 4

Number of sig changing background: 0

5.3 binding vs background changes

Show code
bs <- bs |> mutate(bs, bin = cut(bg.log2FoldChange, breaks = seq(-3,3, 0.5)))

ggplot(bs, aes(x = bin, y = bs.log2FoldChange))+
  geom_violin()+
  geom_boxplot(width = 0.25)

6 Save file

Show code
# rds
saveRDS(bs, paste0(outpath, "merged_bs_diff_oe_2v2_res.rds"))

# beds
# up_bs <- bs |> subset((bs$bs.padj < 0.01) & (bs$bs.log2FoldChange > 0)) |>
#   makeGRangesFromDataFrame(.)
# 
# down_bs <- bs |> subset((bs$bs.padj < 0.01) & (bs$bs.log2FoldChange < 0))|>
#   makeGRangesFromDataFrame(.)
# 
# up_bg <- bs |> subset((bs$bg.padj < 0.01) & (bs$bg.log2FoldChange > 0)) |>
#   makeGRangesFromDataFrame(.)
# 
# down_bg <- bs |> subset((bs$bg.padj < 0.01) & (bs$bg.log2FoldChange < 0))|>
#   makeGRangesFromDataFrame(.)
# 
# rtracklayer::export.bed(up_bs, paste0("merged_bs_upbs_oevsflag.bed"))
# rtracklayer::export.bed(down_bs, paste0("merged_bs_downbs_oevsflag.bed"))
# rtracklayer::export.bed(up_bg, paste0("merged_bs_upbg_oevsflag.bed"))
# rtracklayer::export.bed(down_bg, paste0("merged_bs_downbg_oevsflag.bed"))

7 Session info

Show code
sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ggpointdensity_0.1.0    GenomicFeatures_1.54.1  AnnotationDbi_1.64.0   
 [4] Biobase_2.62.0          dplyr_1.1.3             BindingSiteFinder_2.0.0
 [7] GenomicRanges_1.54.1    GenomeInfoDb_1.38.0     IRanges_2.36.0         
[10] S4Vectors_0.40.1        BiocGenerics_0.48.1     ggplot2_3.4.4          
[13] knitr_1.44             

loaded via a namespace (and not attached):
  [1] RColorBrewer_1.1-3          rstudioapi_0.15.0          
  [3] jsonlite_1.8.7              shape_1.4.6                
  [5] magrittr_2.0.3              ggbeeswarm_0.7.2           
  [7] farver_2.1.1                rmarkdown_2.24             
  [9] GlobalOptions_0.1.2         BiocIO_1.12.0              
 [11] zlibbioc_1.48.0             vctrs_0.6.3                
 [13] Cairo_1.6-1                 memoise_2.0.1              
 [15] Rsamtools_2.18.0            RCurl_1.98-1.13            
 [17] webshot_0.5.5               htmltools_0.5.6            
 [19] S4Arrays_1.2.0              progress_1.2.2             
 [21] distributional_0.3.2        curl_5.0.2                 
 [23] SparseArray_1.2.0           htmlwidgets_1.6.2          
 [25] plyr_1.8.9                  cachem_1.0.8               
 [27] GenomicAlignments_1.38.0    lifecycle_1.0.3            
 [29] iterators_1.0.14            pkgconfig_2.0.3            
 [31] Matrix_1.6-1                R6_2.5.1                   
 [33] fastmap_1.1.1               GenomeInfoDbData_1.2.11    
 [35] MatrixGenerics_1.14.0       clue_0.3-65                
 [37] digest_0.6.33               colorspace_2.1-0           
 [39] DESeq2_1.42.0               RSQLite_2.3.2              
 [41] labeling_0.4.3              filelock_1.0.2             
 [43] fansi_1.0.4                 httr_1.4.7                 
 [45] polyclip_1.10-6             abind_1.4-5                
 [47] compiler_4.3.1              bit64_4.0.5                
 [49] withr_2.5.0                 doParallel_1.0.17          
 [51] BiocParallel_1.36.0         viridis_0.6.4              
 [53] DBI_1.1.3                   ggforce_0.4.1              
 [55] biomaRt_2.58.0              MASS_7.3-60                
 [57] rappdirs_0.3.3              DelayedArray_0.28.0        
 [59] rjson_0.2.21                tools_4.3.1                
 [61] vipor_0.4.5                 beeswarm_0.4.0             
 [63] glue_1.6.2                  restfulr_0.0.15            
 [65] grid_4.3.1                  cluster_2.1.4              
 [67] generics_0.1.3              gtable_0.3.4               
 [69] tidyr_1.3.0                 hms_1.1.3                  
 [71] xml2_1.3.5                  utf8_1.2.3                 
 [73] XVector_0.42.0              foreach_1.5.2              
 [75] pillar_1.9.0                ggdist_3.3.0               
 [77] stringr_1.5.0               circlize_0.4.15            
 [79] tweenr_2.0.2                BiocFileCache_2.10.1       
 [81] lattice_0.21-8              rtracklayer_1.62.0         
 [83] bit_4.0.5                   tidyselect_1.2.0           
 [85] locfit_1.5-9.8              ComplexHeatmap_2.18.0      
 [87] Biostrings_2.70.1           gridExtra_2.3              
 [89] SummarizedExperiment_1.32.0 svglite_2.1.2              
 [91] xfun_0.40                   matrixStats_1.0.0          
 [93] stringi_1.7.12              yaml_2.3.7                 
 [95] kableExtra_1.3.4            evaluate_0.21              
 [97] codetools_0.2-19            tibble_3.2.1               
 [99] cli_3.6.1                   systemfonts_1.0.4          
[101] munsell_0.5.0               Rcpp_1.0.11                
[103] dbplyr_2.4.0                png_0.1-8                  
[105] XML_3.99-0.15               ggrastr_1.0.2              
[107] parallel_4.3.1              blob_1.2.4                 
[109] prettyunits_1.1.1           bitops_1.0-7               
[111] viridisLite_0.4.2           scales_1.2.1               
[113] purrr_1.0.2                 crayon_1.5.2               
[115] GetoptLong_1.0.5            rlang_1.1.1                
[117] KEGGREST_1.42.0             rvest_1.0.3